import math, random

from Card import Card

from CribScore import CribScore

class CribTest:
    # ['s','c','d','h'] Spades, Clubs, Diamonds, Hearts
    # ['a','2','3','4','5','6','7','8','9','t','j','q','k']
    # Ace, ..., Ten, Jack, Queen, King

    suitNames = {'s':"Spades", 'c':"Clubs", 'd':"Diamonds", 'h':"Hearts"}
    rankNames = {'a':"Ace", '2':"2", '3':"3", '4':"4", '5':"5", '6':"6",
                 '7':"7", '8':"8", '9':"9", 't':"Ten", 'j':"Jack", 'q':"Queen",
                 'k':"King"}

    def textName(self, card):
        return "%s of %s" % (self.rankNames[card.getRank()],
                             self.suitNames[card.getSuit()])

    def __init__(self):
        print "===Called __init__"

    def mainLoop(self):
        print "===Called mainLoop"

        # Single Card Object

        cardOne = Card('3', 'h') # 3 of Hearts
        cardTwo = Card('j', 's') # Jack of Spades

        print "Card One is a %s of %s" % (self.rankNames[cardOne.getRank()],
                                          self.suitNames[cardOne.getSuit()])

        print "Card Two is a %s of %s" % (self.rankNames[cardTwo.getRank()],
                                          self.suitNames[cardTwo.getSuit()])

        if (cardOne.getRankNum() < cardTwo.getRankNum()):
            print "Card two is higher"

        # Using a function

        print "Card One is still %s" % self.textName(cardOne)

        # Make a list with the whole deck

        deck = []
        for r in self.rankNames.keys():
            for s in self.suitNames.keys():
                deck.append(Card(r,s))

        random.shuffle(deck)
        print "\n\n-------- Shuffled Deck --------\n"

        for i in range(5):
            print "Card %s is %s" % (i, self.textName(deck[i]))
        
        random.shuffle(deck)
        print "\n\n-------- Shuffled Deck --------\n"

        myHand = deck[:5]

        for card in myHand:
            print "My Hand has a %s" % self.textName(card)

        myScore = CribScore(myHand)

        print "My Hand has a score of " + str(myScore.score())

        print "\n\n===Finished mainLoop"

def main():
    print "===Start main()"
    g = CribTest()
    g.mainLoop()
    print "===End main()"


#this calls the 'main' function when this script is executed
if __name__ == '__main__': main()
